home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / term.exe / TERM.H < prev   
C/C++ Source or Header  |  1992-01-07  |  4KB  |  137 lines

  1. //    Author: Patrick Reilly
  2. //    ID:        70274,161 (Compuserve)
  3. //    Version    1.01
  4.  
  5. //    Contents --------------------------------------------------------------
  6. //
  7. //      KeyMap
  8. //      termbuf
  9. //
  10. //    Description
  11. //
  12. //        Defines the typedef KeyMap, used to map keycodes to terminal
  13. //    emulation strings. Defines the class termbuf, a streambuf-derived
  14. //    class that allows stream-based terminal emulation for use in tele-
  15. //    communication programs.
  16. //
  17. //    End -------------------------------------------------------------------
  18.  
  19. //    Interface Dependencies ------------------------------------------------
  20.  
  21. #ifndef __TERM_H
  22. #define __TERM_H
  23.  
  24. #ifndef __IOSTREAM_H
  25. #include <iostream.h>
  26. #endif
  27.  
  28. #ifndef __CONIO_H
  29. #include <conio.h>
  30. #endif
  31.  
  32. //    End Interface Dependencies --------------------------------------------
  33.  
  34. //    Macros    //
  35.  
  36. #define MAXKEYMAPSIZE    243
  37.  
  38. //    NOTE:
  39. //
  40. //        MAXKEYMAPSIZE is the largest number of entries in a KeyMap. This
  41. //    number is WRONG! 243 was determined experimentally on a laptop computer
  42. //    and is the number of responses (non-duplicate) that I got from a
  43. //    laptop computer using library call bioskey(0). In later upgrades I'll
  44. //    change this number to actively reflect the true number. An alternative
  45. //    is to dynamically allocate mapMatch[], since this is what this macro
  46. //    is used for. This means a bit more error checking though. Of course in
  47. //    use, this macro only needs to be large enough to hold the largest size
  48. //    KeyMap array you're going to use.
  49.  
  50. //    Typedef structure //
  51.  
  52. typedef struct
  53.     {
  54.     unsigned int keycode;    // keycode - returned by bioskey(0).
  55.     char _FAR *string;        // emulation string.
  56.     } KeyMap;
  57.  
  58. //    Description -----------------------------------------------------------
  59. //
  60. //        KeyMap typedef is used to store key mapping information. The member
  61. //    keycode is a keyboard keystroke as returned by the bioskey(0) library
  62. //    function. The most significant byte is the key scan code, the least
  63. //    significant byte is the ascii code. The member string is an asciiz
  64. //    string containing the characters that emulate the required terminal.
  65. //
  66. //    End -------------------------------------------------------------------
  67.  
  68. //    Typedef structure //
  69.  
  70. typedef struct
  71.     {
  72.     int left,top,right,bottom;
  73.     } Rect;
  74.  
  75. //    Description -----------------------------------------------------------
  76. //
  77. //        Typedef structure Rect is used to maintain a rectangular screen
  78. //    coordinate.
  79. //
  80. //    End -------------------------------------------------------------------
  81.  
  82. //    Class //
  83.  
  84. class _CLASSTYPE termbuf : public streambuf
  85.     {
  86.     public:
  87.         //    Constructors //
  88.         _Cdecl termbuf();
  89.         _Cdecl termbuf(char _FAR *,int);
  90.  
  91.         //    Destructor //
  92.         _Cdecl ~termbuf();
  93.  
  94.         // overloaded member from streambuf //
  95.         streambuf _FAR * _Cdecl setbuf(signed char _FAR *,int);
  96.  
  97.         //    extraction method //
  98.         int  _Cdecl underflow();
  99.  
  100.         //    insertion method //
  101.         int  _Cdecl overflow(int=EOF);
  102.  
  103.         // key mapping method //
  104.         void _Cdecl setmap(KeyMap _FAR *);
  105.  
  106.         // console methods //
  107.         void _Cdecl setWindow(Rect&);
  108.         void _Cdecl setWindow(int,int,int,int);
  109.         void _Cdecl setBackground(int);
  110.         void _Cdecl setForeground(int);
  111.         void _Cdecl setAttribute(int);
  112.         void _Cdecl clearWindow();
  113.         void _Cdecl gotoWindow(int,int);
  114.  
  115.     protected:
  116.         // console methods //
  117.         void _Cdecl initScreen();
  118. virtual    void _Cdecl processKey(unsigned int);
  119.  
  120.         KeyMap _FAR *map,_FAR *emap;
  121.         struct text_info ti;
  122.         int insLen,keymapsize;
  123.         char noMap,mapMatch[MAXKEYMAPSIZE];
  124.     };
  125.  
  126. //    Description -----------------------------------------------------------
  127. //
  128. //      Class termbuf is a streambuf-derived class for use with streams
  129. //    that function as terminals. Can be used with class istream (reads the
  130. //    keyboard and converts into terminal emulation strings), class ostream
  131. //    (accepts terminal emulation strings and displays to the console), or
  132. //    with class iostream (acts as both).
  133. //
  134. //    End -------------------------------------------------------------------
  135.  
  136. #endif    // __TERM_H
  137.